package com.lehecai.core.api.user;

import com.lehecai.core.api.AbstractApiResultBean;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Created by He Wang on 2014/11/11.
 */
public class RefundManual extends AbstractApiResultBean {

	public static final String QUERY_RECHARGE_ID = "recharge_id";
	public static final String QUERY_ID = "id";
	public static final String QUERY_UID = "uid";

	public static final String SET_AMOUNT = "amount";

	private String rechargeId;//充值
	private String cardNo;
	private String bankName;
	private Double amount;
	private String bankId;//特殊退款时使用的银行卡id

	public static RefundManual convertFromJSONObject(JSONObject object) {
		if (object == null) {
			return null;
		}
		RefundManual refundManual = new RefundManual();
		refundManual.cardNo = getString(object, "card_no");
		refundManual.bankName = getString(object, "bank_name");
		if (object.containsKey("max_amount") && StringUtils.isNotEmpty(getString(object, "max_amount"))) {
			refundManual.amount = Double.valueOf(getString(object, "max_amount"));
		}
		return refundManual;
	}

	@SuppressWarnings("unchecked")
	public static List<RefundManual> convertFromJSONArray(JSONArray array) {
		if (array == null) {
			return null;
		}
		List<RefundManual> list = new ArrayList<RefundManual>();
		for (Iterator iterator = array.iterator(); iterator.hasNext();) {
			JSONObject object = (JSONObject) iterator.next();
			list.add(convertFromJSONObject(object));
		}
		return list;
	}

	public String getRechargeId() {
		return rechargeId;
	}

	public void setRechargeId(String rechargeId) {
		this.rechargeId = rechargeId;
	}

	public String getCardNo() {
		return cardNo;
	}

	public void setCardNo(String cardNo) {
		this.cardNo = cardNo;
	}

	public Double getAmount() {
		return amount;
	}

	public void setAmount(Double amount) {
		this.amount = amount;
	}

	public String getBankName() {
		return bankName;
	}

	public void setBankName(String bankName) {
		this.bankName = bankName;
	}

	public String getBankId() {
		return bankId;
	}

	public void setBankId(String bankId) {
		this.bankId = bankId;
	}
}
